﻿package com.eve.eplus.main;

import java.util.HashMap;
import java.util.List;

import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.os.Handler;

import com.eve.eplus.common.activity.BaseActivity;
import com.eve.eplus.common.app.BaseApplication;
import com.eve.eplus.common.app.Constants;
import com.eve.eplus.common.app.SettingConstants;
import com.eve.eplus.common.db.MoveDBRunnable;
import com.eve.eplus.common.db.PersistentUtils;
import com.eve.eplus.common.view.ComDialogTools;
import com.eve.eplus.main.logic.SettingUtility;
import com.eve.eplus.model.AccountModel;
import com.eve.eplus.sns.SNSAccountManager;
import com.eve.eplus.R;

/**
 * 欢迎界面
 * 
 * @author Norsie
 * @create 12-11-29
 */
public class WelcomeActivity extends BaseActivity
{

    private Context mContext = WelcomeActivity.this;
    private static int SPLASH_DISPLAY_LENGHT ;// 延迟时间

    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome_main);
        SPLASH_DISPLAY_LENGHT=2000;
        if(!BaseApplication.isFirst) 
            if(SettingUtility.getWelcomeSetting()!=SettingConstants.WELCOME_TRUE)
                SPLASH_DISPLAY_LENGHT=0;
        
        // 判断设备当前是否具备SD卡，若是，正常执行程序，若否，提示用户，退出程序。
        if (android.os.Environment.getExternalStorageState().equals(
                android.os.Environment.MEDIA_MOUNTED))
        {
            // 复制数据库到sd卡
            new Thread(new MoveDBRunnable(this)).start();
        }
        else
        {
            // 提示用户，退出程序
            ComDialogTools.showConfirmDialog(mContext, "错误", "确定", null,
                    "SD卡被拔出，请插入SD卡后重新启动应用！", new OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which)
                {
                    // TODO Auto-generated method stub
                    WelcomeActivity.this.finish();
                }
            }, null);
        }

        //延迟进入登陆界面
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run()
            {
                if(!BaseApplication.isFirst) {
                    // 读取SNS帐号列表
                    BaseApplication.SNS_ACCOUNT=SNSAccountManager.getAccountList();
                    gotoActivityAndFinish(mContext, HomeActivity.class);
                    overridePendingTransition(R.anim.activity_push_up_in,R.anim.activity_push_up_out);
                }
                else
                    gotoActivityAndFinish(mContext, IntroduceActivity.class);
            }

        }, SPLASH_DISPLAY_LENGHT);
    }
    
  

}
